cmake_minimum_required(VERSION 3.10)

# 忽略代码中的中文注释引起的MSVC编译器警告
if(MSVC)
    add_compile_options(/source-charset:utf-8)
    add_compile_options(/execution-charset:utf-8)
endif()

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(PROJECT_NAME "demo")
project(${PROJECT_NAME} VERSION 1.0.0)

find_package(OpenGL REQUIRED COMPONENTS OpenGL)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets REQUIRED)
find_package(GLEW REQUIRED)
find_package(Poco REQUIRED COMPONENTS Foundation)

if(MSVC)
    find_package(PCL REQUIRED)
    find_package(Opencv REQUIRED)
    find_package(VTK REQUIRED)
else()
    set(PCL_DIR "/home/school/lib/pcl-1.13/share/pcl-1.13")
    find_package(PCL 1.13.1 REQUIRED COMPONENTS io)
    set(OpenCV_DIR "/home/school/cxz/Projects/percipient-service/deps/OpenCV/opencv4.5.5_contrib_install/lib/cmake/opencv4")
    find_package(OpenCV REQUIRED PATHS /home/school/cxz/Projects/percipient-service/deps/OpenCV/opencv4.5.5_contrib_install/lib/cmake/opencv4)
endif()

CollectSourceFiles(${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES)
add_executable(${PROJECT_NAME} ${PRIVATE_SOURCES})
set_target_properties(
    ${PROJECT_NAME} PROPERTIES
    BUILD_RPATH "/usr/lib/x86_64-linux-gnu;usr/local/lib"
    )

#依赖库连接
target_compile_definitions(${PROJECT_NAME} PRIVATE DEMO_BUILD)
target_include_directories(${PROJECT_NAME} PUBLIC ${PCL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} PUBLIC isc-lib-lidar)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PCL_LIBRARIES} ${VTK_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets OpenGL::GL GLEW::GLEW)
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})

if(MSVC)
    # 定义需要查找的多个目录
    set(DLL_DIRECTORIES
        ${CMAKE_SOURCE_DIR}/libs/bin
    )
    # copy dll files
    CopyFiles("${PROJECT_NAME}" "${DLL_DIRECTORIES}" "*.dll" $<TARGET_FILE_DIR:${PROJECT_NAME}> PRIVATE_SOURCES)
endif()